# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=meek
pkgver=0.30
pkgrel=3
pkgdesc="A pluggable transport proxy written in Go"
url="https://trac.torproject.org/projects/tor/wiki/doc/meek"
arch="all"
license="CC0-1.0"
depends="ca-certificates"
makedepends="glide go libcap"
subpackages="$pkgname-doc
	$pkgname-server
	"
# no test suite available
options="!check"
source="$pkgname-$pkgver.tar.gz::https://gitweb.torproject.org/pluggable-transports/$pkgname.git/snapshot/$pkgname-$pkgver.tar.gz
	glide.lock
	glide.yaml
	"
builddir="$srcdir/src/$pkgname"

prepare() {
	mkdir -p ${builddir%/*}
	mv "$srcdir/$pkgname-$pkgver" "$builddir"
	cd "$builddir"
	cp "$srcdir"/glide.yaml "$srcdir"/glide.lock .
	export GOPATH="$srcdir"
	glide install --skip-test
	default_prepare
}

build() {
	cd "$builddir"
	export GOPATH="$srcdir"
	go build -v -ldflags "-s -w" \
		-o meek-client/meek-client ./meek-client/...
	go build -v -ldflags "-s -w" \
		-o meek-server/meek-server ./meek-server/...
}

package() {
	cd "$builddir"
	install -Dm 755 meek-client/meek-client "$pkgdir/usr/bin/meek-client"

	mkdir -p "$pkgdir/usr/share/man/man1"
	install -Dm644 doc/*.1 -t "$pkgdir/usr/share/man/man1"
	install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"

	install -Dm644 README "$pkgdir/usr/share/doc/$pkgname/README"
	install -Dm644 meek-client/torrc \
		"$pkgdir/usr/share/doc/$pkgname/torrc.meek-client"
	install -Dm644 meek-server/torrc \
		"$pkgdir/usr/share/doc/$pkgname/torrc.meek-server"
}

server() {
	pkgdesc="meek pluggable transport proxy server"
	depends=
	install -Dm 755 "$builddir"/meek-server/meek-server \
		"$subpkgdir/usr/bin/meek-server"
	setcap 'cap_net_bind_service=+ep' "$subpkgdir/usr/bin/meek-server"
}

glide_init() {
	abuild clean deps unpack prepare
	cd "$builddir"
	export GOPATH="$srcdir"
	rm -f glide.yaml glide.lock
	glide init --non-interactive
	glide update
	cp glide.yaml glide.lock "$startdir"
	cd "$startdir" && abuild checksum clean
}

sha512sums="5dd989d6800f4aaca9e5f66acf325afbb4fea70a8347a1fdff77381b28d5b9762f9d7a45b4375086d9167e1a407e53aa1d1b3203eaa09e3f8e36f2a9805dcc3d  meek-0.30.tar.gz
ccbd369ec5319ed6057c2d980e77612c1f1c2ec8f63a24f8e4dba3ee4f6c2b041050d49753c96f9f7e4d1c759ce0f023fa620250022a1699fbf45893e71fa555  glide.lock
6c04650f2b09db98f3fdce52cc4a2720f16ea3cdf6165dd75ea4f20785138a42635ad608c64b749767a58933ed5115ed720a3a03005f0a426ea1e5e379ff26cd  glide.yaml"
